package com.i2works.smartluolong.web.service.common.impl;

import com.i2works.smartluolong.utils.exception.DAOException;
import com.i2works.smartluolong.utils.exception.ServiceException;
import com.i2works.smartluolong.web.dal.common.dao.IHolidayDAO;
import com.i2works.smartluolong.web.entity.common.HoliDayDO;
import com.i2works.smartluolong.web.entity.common.HoliDayQuery;
import com.i2works.smartluolong.web.service.common.IHolidayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 节假日业务层实现类
 *
 * @author Liu Yutao <koal@vip.qq.com>
 * @date 2018/6/15 11:34
 */

@Service("holidayService")
public class HolidayServiceImpl implements IHolidayService {

    @Autowired
    private IHolidayDAO holidayDAO;


    /**
     * 查询全部
     */
    @Override
    public List<String> queryAll(HoliDayQuery query) throws ServiceException {
        try {
            return holidayDAO.queryAll(query);
        } catch (DAOException e) {
            throw new ServiceException(e);
        }
    }

    /**
     * 删除全部
     */
    @Override
    public void deleteAll() throws ServiceException {
        try {
            holidayDAO.deleteAll();
        } catch (DAOException e) {
            throw new ServiceException(e);
        }
    }

    /**
     * 保存全部
     */
    @Override
    public void saveAll(String[] dateList) throws ServiceException {
        try {
            List<String> strings = holidayDAO.queryAll(new HoliDayQuery());
            List<String> list = Arrays.asList(dateList);
            for (String str : dateList) {
                HoliDayDO holiDayDO = new HoliDayDO();
                holiDayDO.setDate(str);
                holiDayDO.setDateType(0);
                holidayDAO.save(holiDayDO);
            }
        } catch (DAOException e) {
            throw new ServiceException(e);
        }
    }
}
